package com.cg.design.graphicdesignpattern.strategy;

/**
 * 表示进行猜拳游戏的选手的类
 *
 * @program: LeetCode->Player
 * @description: 表示进行猜拳游戏的选手的类
 * @author: cg
 * @create: 2022-03-24 19:15
 **/
public class Player {

    /**
     * 选手姓名
     */
    private final String name;
    /**
     * 选手所使用的猜拳策略
     */
    private final Strategy strategy;
    /**
     * 选手赢的次数
     */
    private int winCount;
    /**
     * 选手输的次数
     */
    private int loseCount;
    /**
     * 选手比赛的次数
     */
    private int gameCount;

    public Player(String name, Strategy strategy) {
        this.name = name;
        this.strategy = strategy;
    }

    /**
     * 通过选手选择的策略获取下一局要出的手势
     *
     * @return
     */
    public Hand nextHand() {
        return strategy.nextHand();
    }

    /**
     * 赢
     */
    public void win() {
        strategy.study(true);
        winCount++;
        gameCount++;
    }

    /**
     * 输
     */
    public void lose() {
        strategy.study(false);
        loseCount++;
        gameCount++;
    }

    /**
     * 平
     */
    public void even() {
        gameCount++;
    }

    @Override
    public String toString() {
        return "[" + name + ":" + gameCount + " games, " + winCount + " win, " + loseCount + " lose]";
    }
}
